﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebStorage.Controllers
{
    public class CheckLoginAttribute : ActionFilterAttribute
    {
        //重写ActionFilterAttribute中的OnActionExecuted方法，表示在执行Action之前执行此方法
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //判断Action方法的Control是否跳过登录验证
            if (filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false))
            {
                return;
            }
            //判断Action方法是否跳过登录验证
            if (filterContext.ActionDescriptor.IsDefined(typeof(SkipCheckLoginAttribute), false))
            {
                return;
            }
            if (filterContext.HttpContext.Session["User"] == null)
            {
                //跳转方法1：
                filterContext.HttpContext.Response.Redirect("/Login/Index");
            }
        }
    }
    public class SkipCheckLoginAttribute : Attribute
    {

    }
}